package com.kfm.ajax.model;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
@ToString(callSuper = true)
public class UserModelDTO extends UserModel implements Serializable{

    private List<RoleModel> roleList;

    private List<MenuModel> menuModelList;

    private List<String> promissionList;

    public UserModelDTO(UserModel userModel, List<RoleModel> roleList){
        super(userModel.getId(), userModel.getUsername(), userModel.getPassword(), userModel.getName(), userModel.getPhone(), userModel.getEmail(), userModel.getAvatar(), userModel.getState(), userModel.getCreateDate(), userModel.getUpdateDate(), userModel.getDeptId());
        this.roleList = roleList;
    }

    public UserModelDTO(UserModel userModel, List<RoleModel> roleList, List<MenuModel> menuModelList){
        super(userModel.getId(), userModel.getUsername(), userModel.getPassword(), userModel.getName(), userModel.getPhone(), userModel.getEmail(), userModel.getAvatar(), userModel.getState(), userModel.getCreateDate(), userModel.getUpdateDate(), userModel.getDeptId());
        this.roleList = roleList;
        this.menuModelList = menuModelList;
        initPromissionList();
    }


    private void initPromissionList(){
        // 判断 menuModelList 是否为空
        if (this.menuModelList != null && this.menuModelList.size() > 0){
            if (this.promissionList == null){
                this.promissionList = new ArrayList<>();
            }
            // 遍历 menuModelList 获取 url
            for (MenuModel menuModel : this.menuModelList) {
                // url 添加到 promissionList
                this.promissionList.add(menuModel.getUrl());
            }
        }
    }
}
